﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using FMPCore;
using FMPCore.Interfaces;

namespace Client
{
    /// <summary>
    /// Interaction logic for winSignup.xaml
    /// </summary>
    public partial class winSignup : Window
    {
        private IMessage m_proxy;
        public winSignup(IMessage proxy)
        {
            m_proxy = proxy;
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        /// <summary>
        /// Get the Username
        /// </summary>
        public string Username
        {
            get
            {
                return txtName.Text;
            }
        }

        /// <summary>
        /// Get the Password
        /// </summary>
        public string Password
        {
            get
            {
                return txtPass1.Password;
            }
        }

        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text == string.Empty || txtPass1.Password == string.Empty || txtPass2.Password == string.Empty)
            {
                MessageBox.Show("Please fill in all fields");
            }
            else if (txtPass1.Password != txtPass2.Password)
            {
                MessageBox.Show("Passwords are not the same");
            }
            else
            {
                if (m_proxy.AddUser(txtName.Text, txtPass1.Password))
                {
                    this.DialogResult = true;
                }
                else
                {
                    MessageBox.Show("Failed to create user.", "Could not create user.", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }                
            }
        }
    }
}
